<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Services\TelnetServer;
use App\Services\CommandHandler;

class StartTelnetServer extends Command
{
    protected $signature = 'telnet:start 
                            {--host=127.0.0.1 : Server host}
                            {--port=8765 : Server port}';
    
    protected $description = 'Start the Telnet server';

    public function handle()
    {
        $host = $this->option('host');
        $port = $this->option('port');

        $this->info("Starting Telnet server on {$host}:{$port}...");
        
        $commandHandler = new CommandHandler();
        $server = new TelnetServer($commandHandler, $host, $port);
        
        // 注册自定义命令（扩展点）
        $this->registerCustomCommands($commandHandler);
        
        $this->info("Server started. Use 'telnet {$host} {$port}' to connect.");
        
        $server->start();
    }

    protected function registerCustomCommands(CommandHandler $handler)
    {
        // 这里可以注册额外的自定义命令
        // 其他开发者可以通过这个方法来扩展命令
    }
}